package ejb;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import dto.InformacionGerencialDTO;

/**
 * Session Bean implementation class AdministrarHistoriaBean
 */
@Stateless
@LocalBean
public class AdministrarInformacionGerencialBean {

    @PersistenceContext(name = "Smerald2")
    EntityManager em;

    @SuppressWarnings("unchecked")
    public List<InformacionGerencialDTO> consultarControlesPorMes() {
        List<InformacionGerencialDTO> info = (ArrayList<InformacionGerencialDTO>) em
                .createQuery(
                        " SELECT NEW dto.InformacionGerencialDTO (date_trunc('month',c.feControl), count(c.feControl)) "
                        + " FROM TControl c GROUP BY date_trunc('month',c.feControl)  ORDER BY date_trunc('month',c.feControl) DESC")
                .setMaxResults(6).getResultList();
        if (info == null) {
            return new ArrayList<InformacionGerencialDTO>();
        }
        return info;
    }

}
